<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <!--  
        1. 转换number
            Number()
                true => 1
                flase => 0
                null => 0
                '' => 0
                undefined => NaN
                数字字符串or科学计数法保留原有数字除字母e之外的字母都直接转为NaN
            parseInt()
                字符串:保留第一个非数字之前的所有数字,其余全部抛弃
                        以非数字开头,则认为是NaN
                其他写法都是NaN
            parseFloat()
                字符串:保留第一个非数字之前的所有数字,其余全部抛弃 (除了第一个字母e和小数点)
                        以非数字开头,则认为NaN
                其他写法都是NaN
    -->
    <script>
        var x = null;
        var x = undefined;
        var x = true;
        var x = false;
        var x = '';
        var x = '5';
        var x = '5.6';
        var x = '2e3';
        var x = 'abc';
        var x = '123abc';
        var x = 'abc123';
        console.log(Number(x));
        console.log('------------- 分隔符 --------------');    
    </script>
    <script>
        var x = null;
        var x = undefined;
        var x = true;
        var x = false;
        var x = '';
        var x = '5';
        var x = '5.6';
        var x = '2e3';
        var x = 'abc';
        var x = '123abc';
        var x = 'abc123';
        console.log(parseInt(x));
        console.log('------------- 分隔符 --------------');    
    </script>
    <script>    
        var x = null;
        var x = undefined;
        var x = true;
        var x = false;
        var x = '';
        var x = '5';
        var x = '5.6';
        var x = '2e3';
        var x = 'abc';
        var x = '123abc';
        var x = 'abc123';
        console.log(parseFloat(x));
        console.log('------------- 分隔符 --------------');    
    </script>
    <!--  
        2. 转为string
            string()
            任意类型都一个转为string
            对象.toString()
            任意数字,字符串,布尔均可转为string
    -->
    <script>
        var x = 10;
        var x = 1.5;
        var x = null;
        var x = undefined;
        var x = 2e3;
        console.log(String(x));
        var x = 10;
        var x = 1.4;
        // var x = null;
        // var x = undefined;
        var x = true;
        var x = false;
        var x = '123';
        var x = 'abc';
        console.log(x.toString());
    </script>
    <!--  
        3. 转为Boolean
            Boolean()
            有八种情况会转为false,其余都是转为true
            * 0
            * -0
            * 0.0
            * NaN
            * ''
            * null
            * undefined
            * false
    -->
    <script>
        var x = 'e38';
        console.log(Number(x));
    </script>
</body>
</html>